package com.gooapple.notepad.ui;


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

import com.gooapple.notepad.model.BookInfo;

public class MyView extends View implements Runnable {

	 private final Paint mPaint;
	 private int mICount = 0;
	 private final TextUtil mTextUtil;
	 private BookInfo   test =new BookInfo();
	 public MyView(Context context) {
	  super(context);
	  mPaint = new Paint();
	  String   string=test.readText().toString();
//	  String string = "測試自動換行(第1行)\n\n测试自动换行(第2行)\n测试自动换行(第3行)\n测试自动换行(第4行)\n测试自动换行(第5行)\n测试自动换行(第6行)\n测试自动换行(第7行)"
//	    + "生活教會了我們什麼，自己的感覺現在已經徹底的隕滅，jfksdjfiowj計算，。項目vklkdjfojeflknvlkx發大水了幾分反擊率啊 垃圾分類撒" +
//	    		"fja生命中彷彿是蒸發了為自己幸福而爭的念頭，一切就這樣的循規蹈矩！";
	  mTextUtil = new TextUtil(string, 15, 150, 300, 80, Color.LTGRAY,
	    0xff00ff, 255, 16);
	  mTextUtil.InitText();
	  new Thread(this).start();
	 }

	 @Override
	 protected void onDraw(Canvas canvas) {
	  super.onDraw(canvas);
	  canvas.drawColor(Color.LTGRAY);
	  mPaint.setAntiAlias(true);
	  if (mICount < 100) {
	   mICount++;
	  }
	  //mPaint.setColor(Color.RED);
	  //canvas.drawText("加載：" + mICount + "%......", 10, 20, mPaint);
	  mTextUtil.DrawText(canvas);
	 }

	 public void run() {
	  Thread.currentThread();
	  while(!Thread.interrupted()) {
	   try {
	    Thread.sleep(10);
	   } catch (Exception ex) {
	    ex.printStackTrace();
	    Thread.currentThread().interrupt();
	   }
	   this.postInvalidate();
	  }
	 }

//	 public boolean onKeyDown(int keyCode, KeyEvent event) {
//
//	  return mTextUtil.KeyDown(keyCode, event);
//	 }
	 public boolean onUp(){
		 
		 return mTextUtil.onUp();
	 }
	 public boolean onDown(){
		 
		 return mTextUtil.onDown();
	 }

}
